<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS常用知识点示例</title>
    <style>
        /* 1. 基础选择器 */
        p {
            color: #333;
            font-size: 16px;
        }

        #header {
            background-color: #f5f5f5;
            padding: 20px;
            text-align: center;
            margin-bottom: 20px;
            border-radius: 8px;
        }

        .section {
            margin: 30px 0;
            padding: 20px;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
        }

        .button {
            display: inline-block;
            padding: 8px 16px;
            border-radius: 4px;
            background-color: #4a6fa5;
            color: white;
            text-decoration: none;
            border: none;
            cursor: pointer;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        /* 2. 组合选择器 */
        nav ul {
            list-style: none;
        }

        nav>ul {
            display: flex;
            gap: 15px;
            justify-content: center;
            background-color: #f0f0f0;
            padding: 10px;
            margin-bottom: 20px;
        }

        h2+p {
            margin-top: 10px;
            color: #666;
        }

        h2~.example {
            margin-left: 20px;
        }

        /* 3. 属性选择器 */
        input[type="text"] {
            width: 100%;
            padding: 8px;
            margin: 5px 0;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        a[href^="https"] {
            color: #0066cc;
            text-decoration: none;
        }

        /* 4. 伪类与伪元素 */
        a:hover {
            text-decoration: underline;
        }

        .list-example li:nth-child(odd) {
            background-color: #f9f9f9;
        }

        input:focus {
            outline: 2px solid #4d90fe;
            border-color: #4d90fe;
        }

        .first-letter-example::first-letter {
            font-size: 200%;
            font-weight: bold;
            color: #4a6fa5;
        }

        .clearfix::after {
            content: "";
            display: table;
            clear: both;
        }

        /* 5. 盒模型 */
        .box {
            width: 100%;
            max-width: 300px;
            height: 200px;
            padding: 20px;
            border: 2px solid #ccc;
            margin: 10px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: center;
            float: left;
        }

        /* 6. 背景属性 */
        .bg-example {
            width: 100%;
            height: 300px;
            background: #f0f0f0 url('https://picsum.photos/id/1048/1200/300') no-repeat center/cover;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
        }

        /* 7. 文本样式 */
        .text-example {
            font-family: 'Georgia', serif;
            font-size: 18px;
            font-weight: 500;
            line-height: 1.8;
            color: #333;
            text-align: center;
            text-decoration: none;
            text-transform: uppercase;
            letter-spacing: 2px;
            margin: 20px 0;
        }

        /* 8. Flexbox布局 */
        .flex-container {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 10px;
            height: 200px;
            background-color: #f5f5f5;
            padding: 10px;
            border-radius: 6px;
        }

        .flex-item {
            flex: 1;
            min-width: 100px;
            height: 80px;
            background-color: #4a6fa5;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 4px;
        }

        /* 9. Grid布局 */
        .grid-container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-template-rows: 100px auto 100px;
            gap: 15px;
            grid-template-areas:
                "header header header"
                "main main sidebar"
                "footer footer footer";
            height: 400px;
            margin: 20px 0;
        }

        .grid-header {
            grid-area: header;
            background-color: #4a6fa5;
            color: white;
            padding: 10px;
            border-radius: 4px;
        }

        .grid-main {
            grid-area: main;
            background-color: #f0f0f0;
            padding: 10px;
            border-radius: 4px;
        }

        .grid-sidebar {
            grid-area: sidebar;
            background-color: #e0e0e0;
            padding: 10px;
            border-radius: 4px;
        }

        .grid-footer {
            grid-area: footer;
            background-color: #333;
            color: white;
            padding: 10px;
            border-radius: 4px;
        }

        /* 10. 定位 */
        .relative-container {
            position: relative;
            height: 300px;
            background-color: #f9f9f9;
            border-radius: 6px;
            margin: 20px 0;
        }

        .absolute-element {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #ff7e5f;
            color: white;
            padding: 15px;
            border-radius: 4px;
        }

        .fixed-element {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 100;
            background-color: #4a6fa5;
            color: white;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            text-decoration: none;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
        }

        /* 11. 动画与过渡 */
        .transition-example {
            width: 100px;
            height: 100px;
            background-color: blue;
            transition: all 0.3s ease;
            margin: 20px auto;
            border-radius: 4px;
        }

        .transition-example:hover {
            width: 200px;
            background-color: red;
        }

        @keyframes rotate {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        .animation-example {
            width: 100px;
            height: 100px;
            background-color: green;
            animation: rotate 2s linear infinite;
            margin: 20px auto;
            border-radius: 4px;
        }

        /* 12. 响应式设计 */
        @media (max-width: 768px) {
            .flex-container {
                flex-direction: column;
                height: auto;
            }

            .grid-container {
                grid-template-columns: 1fr;
                grid-template-rows: auto;
                height: auto;
                grid-template-areas:
                    "header"
                    "main"
                    "sidebar"
                    "footer";
            }

            .box {
                float: none;
                margin: 10px auto;
            }
        }

        /* 13. 变量与计算 */
        :root {
            --primary-color: #4a6fa5;
            --spacing-unit: 8px;
        }

        .variable-example {
            color: var(--primary-color);
            padding: calc(var(--spacing-unit) * 2);
            border: 1px solid var(--primary-color);
            margin: var(--spacing-unit);
        }

        /* 14. 阴影效果 */
        .shadow-example {
            width: 200px;
            height: 100px;
            margin: 20px auto;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
        }

        /* 15. 滤镜效果 */
        .filter-example {
            width: 300px;
            height: 200px;
            margin: 20px auto;
            border-radius: 4px;
            filter: blur(2px) brightness(1.2);
            background: url('https://picsum.photos/id/1015/300/200') no-repeat center/cover;
        }

        /* 16. 渐变 */
        .gradient-example {
            width: 100%;
            height: 150px;
            margin: 20px 0;
            background: linear-gradient(to right, #ff7e5f, #feb47b);
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 20px;
        }

        /* 页面容器 */
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 头部区域 -->
        <header id="header">
            <h1>CSS常用知识点示例集合</h1>
            <p>包含选择器、布局、动画等核心CSS概念的演示</p>
        </header>

        <!-- 导航栏 -->
        <nav>
            <ul>
                <li><a href="#selectors">选择器</a></li>
                <li><a href="#boxmodel">盒模型</a></li>
                <li><a href="#layouts">布局</a></li>
                <li><a href="#animations">动画</a></li>
                <li><a href="#others">其他特性</a></li>
            </ul>
        </nav>

        <!-- 选择器部分 -->
        <section id="selectors" class="section">
            <h2>1. 选择器示例</h2>
            <p>展示各种CSS选择器的使用方法</p>

            <div class="example">
                <h3>属性选择器</h3>
                <input type="text" placeholder="这是文本输入框">
                <input type="password" placeholder="这是密码输入框">
                <br>
                <a href="https://example.com">外部链接（https开头）</a>
                <a href="/internal">内部链接</a>
            </div>

            <div class="example">
                <h3>伪类与伪元素</h3>
                <p class="first-letter-example">这段文字的首字母会被特殊样式化（伪元素）</p>

                <h4>列表项（奇偶不同样式）：</h4>
                <ul class="list-example">
                    <li>列表项 1</li>
                    <li>列表项 2</li>
                    <li>列表项 3</li>
                    <li>列表项 4</li>
                    <li>列表项 5</li>
                </ul>
            </div>
        </section>

        <!-- 盒模型部分 -->
        <section id="boxmodel" class="section">
            <h2>2. 盒模型示例</h2>
            <p>展示CSS盒模型的基本概念，包含边框、内边距和外边距</p>

            <div class="example clearfix">
                <div class="box">
                    盒模型 1
                </div>
                <div class="box">
                    盒模型 2
                </div>
                <div class="box">
                    盒模型 3
                </div>
            </div>

            <div class="example">
                <h3>背景属性示例</h3>
                <div class="bg-example">
                    背景图片与颜色示例
                </div>
            </div>

            <div class="example">
                <h3>文本样式示例</h3>
                <p class="text-example">这是一段应用了多种文本样式的文字</p>
            </div>
        </section>

        <!-- 布局部分 -->
        <section id="layouts" class="section">
            <h2>3. 布局示例</h2>
            <p>展示Flexbox和Grid等现代布局技术</p>

            <div class="example">
                <h3>Flexbox布局</h3>
                <div class="flex-container">
                    <div class="flex-item">项目 1</div>
                    <div class="flex-item">项目 2</div>
                    <div class="flex-item">项目 3</div>
                    <div class="flex-item">项目 4</div>
                </div>
            </div>

            <div class="example">
                <h3>Grid布局</h3>
                <div class="grid-container">
                    <div class="grid-header">头部区域</div>
                    <div class="grid-main">主要内容区域</div>
                    <div class="grid-sidebar">侧边栏区域</div>
                    <div class="grid-footer">底部区域</div>
                </div>
            </div>

            <div class="example">
                <h3>定位示例</h3>
                <div class="relative-container">
                    <div class="absolute-element">绝对定位元素（居中）</div>
                </div>
            </div>
        </section>

        <!-- 动画部分 -->
        <section id="animations" class="section">
            <h2>4. 动画与过渡示例</h2>
            <p>展示CSS过渡和动画效果</p>

            <div class="example">
                <h3>过渡效果（鼠标悬停查看）</h3>
                <div class="transition-example"></div>
            </div>

            <div class="example">
                <h3>动画效果（自动旋转）</h3>
                <div class="animation-example"></div>
            </div>
        </section>

        <!-- 其他特性部分 -->
        <section id="others" class="section">
            <h2>5. 其他CSS特性</h2>
            <p>展示CSS变量、阴影、滤镜和渐变等效果</p>

            <div class="example">
                <h3>CSS变量示例</h3>
                <p class="variable-example">这个元素使用了CSS变量定义的颜色和间距</p>
                <p class="variable-example">另一个使用相同CSS变量的元素</p>
            </div>

            <div class="example">
                <h3>阴影效果</h3>
                <div class="shadow-example">盒阴影与文本阴影示例</div>
            </div>

            <div class="example">
                <h3>滤镜效果</h3>
                <div class="filter-example"></div>
                <p>上方图片应用了模糊和亮度滤镜</p>
            </div>

            <div class="example">
                <h3>渐变效果</h3>
                <div class="gradient-example">线性渐变背景示例</div>
            </div>
        </section>

        <!-- 回到顶部按钮 -->
        <a href="#" class="fixed-element">↑</a>
    </div>
</body>

</html>